<template>
  <div>
    <!--分类选择-->
    <choice :dynastyList="dynastyList" v-on:listenToChildEvent="getChoice"></choice>

    <!--拍品列表-->
    <product-list :productList="productList" :release="proRelease" :fixedPrice="fixedPrice" :deal="deal"></product-list>

    <pagination :total="total" v-on:listenToChildEvent="getPageIndex"></pagination>
  </div>
</template>

<script>
  import {ipconfig} from '../../../assets/js/ipconfig';
  import {getStatusMapByKey} from '../../../assets/js/tools';
  import {getDynastyList,getProductList} from '../../../assets/js/getData';
  export default {
    name: "productLots",
    data(){
      return {
        resUrl:ipconfig.resUrl,//图片、视频、音频等资源访问路径

        productList:[],//当前显示拍品列表
        total:null,//总页数
        dynastyList:[],//朝代分类
        proRelease:null,////拍品状态：已发布
        deal:null,//拍品状态：已成交
        fixedPrice:null,//
        choiceObj:{
          pageSize:10,//每页显示
          pageNum:1,//第几页
          name:null,
          shopId:null,//店铺ID
          userId:null,//用户ID
          dynastyName:null,
          type:null,//拍品类别：null 全部拍品，1一口价 2竞拍
          status:getStatusMapByKey('eProductStatus').inAuction.val,//拍品状态：11：预展中 12：竞拍中
          descType:getStatusMapByKey('eOrderByType').bySynthesisDesc.val,//排序：2综合排序，2浏览次数多到少，3浏览次数少到多，4收藏最多，5即将结拍，6价格高到低，7价格低到高，8出价次数高到低，9出价次数低到高
          dynastyId:null,//朝代ID
          currentPriceMin:null,//最低价
          currentPriceMax:null,//最高价
          startTime:null,//开始时间
          endTime:null,//结束时间
        }


      }
    },
    created(){
      this.choiceObj.shopId = this.$route.query.shopId;
      this.choiceObj.userId = this.$route.query.userId;
      this.choiceObj.name = this.$route.query.keyword;
      this.choiceObj.dynastyName = this.$route.query.dynastyName;
      this.proRelease = getStatusMapByKey('eProductStatus').release.val;
      this.deal = getStatusMapByKey('eProductStatus').deal.val;
      this.fixedPrice = getStatusMapByKey('eProductType').fixedPrice.val;

      this.getProductList(this.choiceObj);

      //获取朝代分类
      getDynastyList({
        shopId:this.choiceObj.shopId,
        userId:this.choiceObj.userId
      }).then(res => {
        if(res.data.reqResult.code>0){
          this.dynastyList = res.data.data;
        }else {
          Toast(res.data.reqResult.msg);
        }
      })
    },
    methods:{
      getChoice(choiceObj){
        this.choiceObj.type = choiceObj.type;
        this.choiceObj.status = choiceObj.status;
        this.choiceObj.descType = choiceObj.descType;
        this.choiceObj.dynastyId = choiceObj.dynastyId;
        this.choiceObj.currentPriceMin = choiceObj.currentPriceMin;
        this.choiceObj.currentPriceMax = choiceObj.currentPriceMax;
        this.choiceObj.startTime = choiceObj.startTime;
        this.choiceObj.endTime = choiceObj.endTime;

        this.getProductList(this.choiceObj);
      },
      getPageIndex(pageIndex){
        this.choiceObj.pageNum = parseInt(pageIndex);
        this.getProductList(this.choiceObj);
      },
      //获取拍品列表
      async getProductList(choiceObj){
        let res = await getProductList(choiceObj);
        if(res.data.reqResult.code>0){
          this.productList = res.data.data;
          this.total = Math.ceil(res.data.total / this.choiceObj.pageSize);
        }else {
          Toast(res.data.reqResult.msg);
        }
      },

    }


  }
</script>

<style scoped>

</style>
